package com.casa.POI.dianping;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.StatelessSession;
import org.hibernate.criterion.Property;

public class FixRegionExecutor extends Executor {

	@SuppressWarnings("unchecked")
	@Override
	public void execute() {
		StatelessSession s = SessionManager.getInstance().openStatelessSession();
		while (true) {
			Criteria c = s.createCriteria(Shop.class);
			c.add(Property.forName("region").eq(""));
			c.setMaxResults(ConfigurationManager.getInstance().getBatchSize());
			List<Shop> shops = c.list();
			if (shops.size() == 0)
				break;
			s.beginTransaction();
			for (Shop shop : shops) {
				shop.setRegion(null);
				shop.setRegionUrl(null);
				s.update(shop);
				increaseCounter();
				printStatus("fix region of %s", shop.getUrl());
			}
			s.getTransaction().commit();
		}
		s.close();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new FixRegionExecutor().execute();
	}

}
